home *** CD-ROM | disk | FTP | other *** search
/ 10,000 Great Games / 10,000 Great Games.iso / Product / 66 / data1.cab / Source_Files / Src / Player.cpp < prev    next >
C/C++ Source or Header  |  2000-01-16  |  4KB  |  184 lines

  1. #include "stdafx.h"
  2.  
  3. #include <string.h>
  4.  
  5. int names_visible = FALSE, no_armor = FALSE;
  6. cPlayer *players = 0, *first_at_end;
  7. char pl_name[kMaxPlayers][16];
  8. int pl_selected[kMaxPlayers];
  9.  
  10. void cPlayer::make()
  11.     // Make players
  12.  
  13.     cProperties *p = cProperties::find_first("PLAYER");
  14.  
  15.     if (pl_selected[0] && p != 0)
  16.     {
  17.         new cPlayer (p, pl_name[0], new cKeyboard(0));
  18.         p = cProperties::find_next();
  19.         if (!p) p = cProperties::find_first("PLAYER");
  20.     }
  21.  
  22.     if (pl_selected[1] && p != 0)
  23.     {
  24.         new cPlayer (p, pl_name[1], new cKeyboard(1));
  25.         p = cProperties::find_next();
  26.         if (!p) p = cProperties::find_first("PLAYER");
  27.     }
  28.  
  29.     if (pl_selected[2] && p != 0)
  30.     {
  31.         new cPlayer (p, pl_name[2], new cKeyboard(2));
  32.         p = cProperties::find_next();
  33.         if (!p) p = cProperties::find_first("PLAYER");
  34.     }
  35.     
  36.     if (pl_selected[3] && p != 0)
  37.     {
  38.         new cPlayer (p, pl_name[3], new cMouse);
  39.         p = cProperties::find_next();
  40.         if (!p) p = cProperties::find_first("PLAYER");
  41.     }
  42.     
  43.     if (pl_selected[4] && p != 0)
  44.     {
  45.         new cPlayer (p, pl_name[4], new cJoystick(0));
  46.         p = cProperties::find_next();
  47.         if (!p) p = cProperties::find_first("PLAYER");
  48.     }
  49.  
  50.     if (pl_selected[5] && p != 0)
  51.     {
  52.         new cPlayer (p, pl_name[5], new cJoystick(1));
  53.         p = cProperties::find_next();
  54.         if (!p) p = cProperties::find_first("PLAYER");
  55.     }
  56.  
  57.     if (pl_selected[6] && p != 0)
  58.     {
  59.         new cPlayer (p, pl_name[6], new cJoystick(2));
  60.         p = cProperties::find_next();
  61.         if (!p) p = cProperties::find_first("PLAYER");
  62.     }
  63.  
  64.     if (pl_selected[7] && p != 0)
  65.     {
  66.         new cPlayer (p, pl_name[7], new cJoystick(3));
  67.         p = cProperties::find_next();
  68.         if (!p) p = cProperties::find_first("PLAYER");
  69.     }
  70. }
  71.  
  72. cPlayer::cPlayer(cProperties *_orig, const char *_name, cController *c)
  73.         : cCharacter(_orig)
  74. {          
  75.     add_end((cList **)&players);
  76.     
  77.     // Setup controller
  78.     
  79.     controller = c;
  80.     controller->reset();
  81.     
  82.     // Put player in bubble
  83.     
  84.     new cBubble(CHAR_VBUBBLE + rnd(CHAR_RVBUBBLE), this);
  85.     
  86.     // For clarity show name
  87.     
  88.     name = strdup(_name);
  89.     set_text_above(name, 4 * sec);
  90.  
  91.     // Setup score system
  92.  
  93.     score = 0;
  94.     hit_counter = 0;
  95.     scorelist = 0;
  96.     new cScore(this);
  97. }
  98.  
  99. cPlayer::~cPlayer()
  100. {
  101.     free(name);
  102.  
  103.     delete controller;
  104.  
  105.     scorelist->delete_list();
  106. }
  107.  
  108. int cPlayer::control()
  109.     // Do movement/animation etc
  110.     
  111.     if (!cCharacter::control())
  112.     {
  113.         // Revive player
  114.         
  115.         revive();
  116.         
  117.         // Reset controller
  118.         
  119.         controller->reset();
  120.         
  121.         // Put player in bubble
  122.         
  123.         new cBubble(CHAR_VBUBBLE + rnd(CHAR_RVBUBBLE), this);
  124.         
  125.         // Show name for clarity
  126.         
  127.         set_text_above(name, 3 * sec);
  128.     }
  129.  
  130.     // Names always visible?
  131.  
  132.     if (names_visible && *get_text_above() == 0)
  133.         set_text_above(name, 4 * sec);
  134.  
  135.     // Check end level
  136.     
  137.     if (y > surface->total_h && first_at_end == 0)
  138.     {
  139.         first_at_end = this;
  140.  
  141.         modify_score(100);
  142.  
  143.         cScore::determine_winner();
  144.     }
  145.     
  146.     // Control character
  147.     
  148.     controller->determine(this);
  149.     
  150.     return TRUE;
  151. }
  152.  
  153. void cPlayer::hit(int armor_power)
  154. {
  155.     cCharacter::hit(no_armor && armor_power > 0? 1000:armor_power);
  156. }
  157.  
  158. void cPlayer::modify_score(int delta_score, cGameObject *who)
  159. {
  160.     // Count score
  161.  
  162.     score += delta_score;
  163.  
  164.     // We're only interested in other player objects
  165.  
  166.     if (dynamic_cast<cPlayer *>(who) == 0)
  167.         return;
  168.  
  169.     // Keep who we hit
  170.  
  171.     for (cScoreList *l = scorelist; l != 0 && l->who != who; l = (cScoreList *)l->next);
  172.         
  173.     if (l != 0)
  174.         l->score += delta_score;
  175.     else
  176.         new cScoreList(&scorelist, delta_score, who);
  177.  
  178.     // Increase hit counter
  179.  
  180.     hit_counter++;
  181. }
  182.